package com.java.tutorials.jdk7.files;
import com.java.tutorials.Constants;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
 * Created by xuzhike on 2016/1/26.
 * http://www.java2s.com/Code/Java/JDK-7/CreateBufferReaderfromFilesclass.htm
 * Create BufferReader from Files class
 */
public class CreateBufferReaderfromFiles {
    public static void main(String[] args) {
        try (BufferedReader inputReader = Files.newBufferedReader(
                Paths.get(new URI("file:///"+ Constants.TEST_FILE_WITH_PATH)),
                Charset.defaultCharset());

             BufferedWriter outputWriter = Files.newBufferedWriter(
                     Paths.get(new URI("file:///C:/users.bak")),
                     Charset.defaultCharset())) {

            String inputLine;
            while ((inputLine = inputReader.readLine()) != null) {
                outputWriter.write(inputLine);
                outputWriter.newLine();
            }
            System.out.println("Copy complete!");
        } catch (URISyntaxException | IOException ex) {
            ex.printStackTrace();
        }

    }
}
